package elephant.rpc;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.parser.ParserConfig;

import elephant.rpc.client.RPCClient;
import elephant.rpc.client.core.RPCServerInfo;
import elephant.utils.DumpUtil;

/**
 * 
 * @author skydu
 *
 */
public class DemoRPCClient {
	//
	private static Logger logger=LoggerFactory.getLogger(DemoRPCClient.class);
	//
	public static void main(String[] args) throws Exception {
		ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
		//
		RPCClient rpcClient=new RPCClient();
		RPCServerInfo serverInfo=new RPCServerInfo("DemoRPCServer","127.0.0.1",5002);
		rpcClient.addRPCServerInfo(serverInfo);
		rpcClient.init();
		rpcClient.start();
		//
		DemoService demoService=rpcClient.createSyncRemote(DemoService.class,"DemoRPCServer");
		int retcode=demoService.echo("Hello Elephant!");
		logger.debug("retcode:{}",retcode);
		//
		User user=demoService.getUserById(1);
		logger.debug("user:{}",DumpUtil.dump(user));
		//
		List<User> users=demoService.getUsers();
		logger.debug("users:{}",DumpUtil.dump(users));
		//
		byte[] fileContent=demoService.getFileContent("1");
		logger.debug("fileContent:{}",fileContent.length);
	}
}
